﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HaiFang
{
    public partial class UserOperateLogMgr : SampleGridTemplate
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.txbBeginDate.Value = DateTime.Now.Subtract(TimeSpan.FromDays(30)).ToString("yyyy-MM-dd");
                this.txbEndDate.Value = DateTime.Now.ToString("yyyy-MM-dd");

                IList<UserInfoWithGroup> ui= ProxyUserInfo.QueryUserInfo(WebHelper.GetCurrentUserID(),1,0);
                ui.Insert(0,new UserInfoWithGroup(){ AutoID=0,UserName="所有用户"});
                this.ddlUserInfo.DataSource = ui;
                this.ddlUserInfo.DataValueField = "AutoID";
                this.ddlUserInfo.DataTextField = "UserName";
                this.ddlUserInfo.DataBind();

                this.GridBind(this.OrderBy, 1, this.PageControls.PageSize, out m_lTotalRowCount);
            }
        }

        protected override void SetUserControl()
        {
            this.KeyValue = this.keyValue;
            this.ObjectGrid = this.dgDataGrid;
            this.BtnBack2Grid = this.btnBack2Grid;
            this.BtnSave = this.btnSave;
            this.GridPanel = this.gridPanel;
            this.DetailPanel = this.detailPanel;
            this.InformationPanel = this.informationPanel;
            this.LabelInformation = this.labelInformation;
            this.DeleteButtonCellIndex = 2;
            this.DeleteButtonName = "btDelete";

            this.PageControls = this.pageControl;
            this.OrderBy = "";
        }

        public override void GridBind(string sOrderBy, int nPageJump, int nPageSize, out int RecordNum)
        {
            int CurrUserID = WebHelper.GetCurrentUserID();
            DateTime dtBegin = Convert.ToDateTime(this.txbBeginDate.Value);
            DateTime dtEnd = Convert.ToDateTime(this.txbEndDate.Value).AddDays(1);
            int UserID =Convert.ToInt32(this.ddlUserInfo.SelectedValue);
            int Type = 0;
            int PageFirst = nPageJump > 1 ? 1 : 0;
            int PageNum = 0;
            RecordNum = 0;

            IList<UserOperateLog> list = ProxyUserOperateLog.QueryUserOperateLog(CurrUserID, dtBegin, dtEnd, UserID,
                                        Type, PageFirst, nPageSize, nPageJump, out RecordNum, out PageNum);
            this.dgDataGrid.DataSource = list;
            this.dgDataGrid.DataBind();
            if (nPageJump == 1)
            {
                this.pageControl.TotalRows = RecordNum;
            }
            else
            {
                RecordNum = this.pageControl.TotalRows;
                this.pageControl.TotalRows = RecordNum;
            }
        }

        public override void BindObject2DetailPanel(string tmpltId)
        {
        }

        public override void ClearDetailPanel()
        {
        }

        public override void Save(object ob)
        {
        }

        public override void Update(object ob)
        {
        }

        public override void Delete(object KeyObject)
        {
        }

        protected override void BtnCreate_Click(object sender, EventArgs e)
        {
        }

        public override object GetValueFromDetailPanel()
        {
            return null;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.GridBind(this.OrderBy, 1, this.PageControls.PageSize, out m_lTotalRowCount);
        }
    }
}